package za.org.jcicada.genss.sensor.impl;

import java.io.Serializable;

import za.org.jcicada.genss.sensor.SensorStatus;

public class SensorStatusValue implements Serializable {

	/** The serial version ID */
	private static final long serialVersionUID = 1L;

	/** The status of the sensor */
	private SensorStatus status;

	/** The timestamp associated with this value */
	private long time;

	/** The message associated with the status */
	private String message;

	/**
	 * Construct object with all parameters specified.
	 * 
	 * @param status
	 *            the current status
	 * @param time
	 *            the desired timestamp
	 * @param message
	 *            the sensor status message
	 */
	public SensorStatusValue(SensorStatus status, long time, String message) {
		this.status = status;
		this.time = time;
		this.message = message;
	}

	/**
	 * Construct object with all parameters specified.
	 * 
	 * @param status
	 *            the current status
	 * @param time
	 *            the desired timestamp
	 */
	public SensorStatusValue(SensorStatus status, long time) {
		this(status, time, null);
	}

	/**
	 * Construct object and fill in the current time
	 * 
	 * @param status
	 *            the current status
	 * @param message
	 *            the sensor status message
	 */
	public SensorStatusValue(SensorStatus status, String message) {
		this(status, System.currentTimeMillis(), message);
	}

	/**
	 * Construct object and fill in the current time
	 * 
	 * @param status
	 *            the current status
	 */
	public SensorStatusValue(SensorStatus status) {
		this(status, System.currentTimeMillis());
	}

	public SensorStatus getStatus() {
		return status;
	}

	public long getTime() {
		return time;
	}

	public String getMessage() {
		return message;
	}

	@Override
	public boolean equals(Object aOther) {
		if (this == aOther)
			return true;
		if (!(aOther instanceof SensorStatusValue))
			return false;
		SensorStatusValue other = (SensorStatusValue) aOther;
		if (!(status == null ? other.status == null : status.equals(other.status)))
			return false;
		if (!(message == null ? other.message == null : message.equals(other.message)))
			return false;
		return time == other.time;
	}

	@Override
	public int hashCode() {
		return status.ordinal() + (int) time + (message == null ? 0 : message.hashCode());
	}

	@Override
	public String toString() {
		return String.format("%s: %s", getStatus(), getMessage());
	}

}
